package cc.lucien.map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class MapTest {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();

        // 添加数据
        map.put("age", "22");
        map.put("school", "xbmu");
        // 容器大小
        System.out.println(map.size());
        // 遍历map
        Set<Map.Entry<String, String>> set = map.entrySet();
        Iterator<Map.Entry<String, String>> iterator = set.iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, String> next = iterator.next();
            System.out.println(next.getKey() +"="+ next.getValue());
        }
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++");
        // 遍历map2
        Set<String> keySet = map.keySet();
        for (String s : keySet) {
            System.out.println(s +"=" +map.get(s));
        }
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++");
        Iterator<String> iterator1 = keySet.iterator();
        while (iterator1.hasNext()) {
            String key = iterator1.next();
            System.out.println(key +"="+ map.get(key));
        }
    }
}
